﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Markup;
using System.Windows.Media;

namespace TanmiaGrp.GeneralLedger.WinApp
{
    public class BalanceToColorConverter : MarkupExtension, IValueConverter
    {
        private static BalanceToColorConverter converter;

        public BalanceToColorConverter()
        {
        }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (converter == null)
                converter = new BalanceToColorConverter();

            return converter;
        }

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double result = 0;
            if (double.TryParse(value.ToString(), out result))
                if (result > 0)
                    return Brushes.LightGreen;
                else if (result < 0)
                    return Brushes.LightPink;

            return Brushes.White;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
